package com.smartwebx.ha.dal.realtime.sqlprovider;

import static org.apache.ibatis.jdbc.SqlBuilder.FROM;
import static org.apache.ibatis.jdbc.SqlBuilder.SELECT;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.time.DateUtils;

import com.smartwebx.ha.dal.config.OracleConfigInfo;
import com.smartwebx.ha.dal.usebean.enu.FlowTypeEnum;

public class WasProvider {
	private String ST_WASAV_R = OracleConfigInfo.REALTIME_NAME + ".ST_WAS_R";
	
	public String getDayFlowerProcessSQL(Map<String, Object> maps) {
		Date endDate = (Date) maps.get("endDate");
		FlowTypeEnum type = (FlowTypeEnum) maps.get("type");
		endDate = DateUtils.addHours(endDate, 8);
		maps.put("endDate", endDate);
		
		if (type == FlowTypeEnum.AVGFLOWER) { // 平均流量
			SELECT("AVGTQ val,IDTM tm");
			WHERE("STCD = #{stcd}");
			WHERE("IDTM > #{startDate}");
			WHERE("IDTM <= #{endDate}");
			WHERE("STTDRCD = '1'");
		} else if (type == FlowTypeEnum.DAYFLOWER) { // 日流量
			SELECT("TM tm,TGTQ val");
			WHERE("STCD = #{stcd}");
			WHERE("TM > #{startDate}");
			WHERE("TM <= #{endDate}");
		}
		FROM(ST_WASAV_R);
		return SQL();
	}
}
